import 'package:flutter/material.dart';

// GridView 是一个用于展示可滚动的网格布局组件
// 使用默认构造好书构建

class GridViewWidget extends StatelessWidget {
  const GridViewWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.amber,
        title: const Text('案例-GridView'),
      ),
      // 固定测周(水平)方向子元素个数, 无论如何旋转屏幕测轴子元素个数永远不变
      body: GridView(
        gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
          // 设置侧首方向子元素个数,此时每行展示的子元素个数是固定的
          crossAxisCount: 3,
          // 设置主轴方向子元素间距
          mainAxisSpacing: 10,
          // 设置测周方向子元素间距
          crossAxisSpacing: 5,
          // 设置子元素宽高比, 默认宽高相同
          childAspectRatio: 1.0,
        ),
        children: [
          Container(
            color: Colors.red,
            alignment: Alignment.center,
            child: Text("我学习我无敌"),
          ),
          Container(
            color: Colors.blue,
            alignment: Alignment.center,
            child: Text("我学习我牛逼"),
          ),
          Container(
            color: Colors.brown,
            alignment: Alignment.center,
            child: Text("我学习我不愚"),
          ),
          Container(
            color: Colors.cyan,
            alignment: Alignment.center,
            child: Text("我学习去去去"),
          ),
          Container(
            color: Colors.deepPurpleAccent,
            alignment: Alignment.center,
            child: Text("我学习怕个屁"),
          ),
          Container(
            color: Colors.green,
            alignment: Alignment.center,
            child: Text("我学习专干你"),
          ),
        ],
      ),
    );
  }
}
